import { ref } from "vue"
import type { AddVisitParams } from "@/api/addVisit/types"
function useViewModel() {
	//表单校验
	const rules = {
		projectId: [
			{
				required: true,
				message: '请选择项目',
				trigger: ['blur', 'change'],
			},
		],
		visitDate: [
			{
				required: true,
				message: '请选择跟进日期',
				trigger: ['blur', 'change'],
			},
		],
		visitContent: [
			{
				required: true,
				message: '请输入跟进内容',
				trigger: ['blur', 'change'],
			},
		],
		// intentionLevel: [
		// 	{
		// 		required: true,
		// 		message: '请选择意向度',
		// 		trigger: ['blur', 'change'],
		// 	},
		// ],
		// cooperationStatus: [
		// 	{
		// 		required: true,
		// 		message: '请选择合作状态',
		// 		trigger: ['blur', 'change'],
		// 	},
		// ],
		remark: [
			{
				required: false,
				message: '请输入备注',
				trigger: ['blur', 'change'],
			},
		],

	};


	//时间选择器最早的时间
	let minDate = () : number => {
		const now = new Date();
		const year = now.getFullYear() - 10;
		const month = now.getMonth();
		const day = now.getDate();
		const dateTenYearsAgo = +new Date(year, month, day);
		return dateTenYearsAgo;
	}
	let maxDate = () : number => {
		const now = new Date();
		const year = now.getFullYear() + 10;
		const month = now.getMonth();
		const day = now.getDate();
		const dateTenYearsLater = +new Date(year, month, day);
		return dateTenYearsLater;
	}

	//时间选择器开关
	let firstContactDate_visible = ref<boolean>(false)
	//打开时间选择器
	let showFirstContactDate = () : void => {
		firstContactDate_visible.value = true
	}
	//时间选择器-确认
	let firstContactDate_confirm = (e : any) : string => {
		let { value } = e
		firstContactDate_visible.value = false
		return value
	}

	//表单数据
	let formData = ref<AddVisitParams>({
		enterpriseName: '',
		projectId: '',
		remark: '',
		visitContent: '',
		intentionLevel: '',
		cooperationStatus: '',
		visitDate: '',
		visitId: ""
	})

	return {
		rules,
		formData,
		minDate,
		maxDate,
		firstContactDate_visible,
		firstContactDate_confirm,
		showFirstContactDate,
	}
}

export default useViewModel